// import { reqgetUsersByPage ,reqRegister,reqLogin} from "@/api";
import {register,login} from "@/api"
const state = {
    usersMsgList: [],
    loginUserMsg:[],
    isLogin:false
};
//mutions是唯一修改state的地方
const mutations = {
    GETUSERSBYPAGE(state, usersMsgList) {
      state.usersMsgList = usersMsgList;
    },
    LOGIUSERNIFO(state,loginUserMsg){
      state.loginUserMsg = loginUserMsg;
      state.isLogin=true;
    },
    //注册code
    RESSUSECC(state,resCode){
      state.resCode = resCode;
    },
    CLEAR(state){
      //帮仓库中先关用户信息清空
      state.isLogin=false;
    }
};
const actions = {
  //分页获取用户列表
  /*async getUsersByPage({ commit },{pageNum,pageSize}) {
    //reqgetUsersByPage返回的是一个Promise对象
    //需要用await接受成功返回的结果，await必须要结合async一起使用（CP）
    let result = await reqgetUsersByPage(pageNum,pageSize);
    if (result.code == 200) {
      commit("GETUSERSBYPAGE", result.data.result);
    }
  },
  */
  //用户登录
   async login({ commit },{uaccount,upwd}) {
    //reqgetUsersByPage返回的是一个Promise对象
    //需要用await接受成功返回的结果，await必须要结合async一起使用（CP）
    let result = await login(uaccount,upwd);
    console.log(result.code)
    return result.code;
    if (result.code == 200) {
<<<<<<< HEAD
      console.log(result.data)
      // return result.data
=======
      commit("LOGIUSERNIFO", result.data);
      return "ok"

  //  }else{
     
>>>>>>> 96896841aafe7d22cfb2da53a795907c51e06db1
   }
  },
  
//  login({ commit }, uaccount, upwd){
//   console.log(uaccount, upwd);
//   return new Promise((resolve, reject) => {
//     login({uaccount: uaccount, upwd: upwd})
//       .then(() => {

//         resolve();
//       })
//       .catch((error) => {
//         reject(error);
//       })
//   })
//  },
  //用户注册
  async register({ commit },userMsg) {
    //reqgetUsersByPage返回的是一个Promise对象
    //需要用await接受成功返回的结果，await必须要结合async一起使用（CP）
    let result = await register(userMsg);
    return  result.code;
  },
  async userLogout({commit}) {
    commit("CLEAR");
  },
  
};
//计算属性
const getters = {};
export default {
  state,
  mutations,
  actions,
  getters,
};
